

class MiApiLogList extends BaseTableList  {

    constructor(props) {
        super(props);
        this.fixedKey="id";
        this.filter = [ 'tag_name_list' ];
        this.fetchUrl="/img2data/apiLog/list"
        this.actioncolumns = true;
        this.actionWidth=100;
        this.placeholder="请输入请求id";
        this.state.filter= {  tag_name_list: ''};
        this.columns=this.getColumns();

    }


    res_data = {
        id: {
            label: 'id',
            width: 80
        },
        requestId: {
            label: '请求id',
            width: 100
        },
        gmtCreate: {
            label: '创建时间',
            width: 200
        },
        step: {
            label: '步骤',
            width: 50
        },
        name: {
            label: '名称',
            width: 120
        },
        res: {
            label: '结果',
            width: 600
        },

    }


    componentDidMount() {
        let state= M.GetStateSession();
        if(state && state.requestId){
            let requestId=state.requestId;
            this.state.pagination.keywords = requestId;
        }
        this.fetch();
    }


    componentWillUnmount(){
        M.SetStateSession({})
    }

    async fetch() {
        this.setState({ loading: true });
        let { current,pageSize,keywords,order,filter } = this.state.pagination;
        let r=await window.M.request.get(this.fetchUrl,{
            page: current,
            num: pageSize,
            keywords: keywords,
            order: order,
            ...filter
        })
        let total =r.data.total;
        const pagination = { ...this.state.pagination };
        pagination.total = total;
        this.setState({
            pagination,
            data: r.data.dataList,
            loading: false
        })
    }

    actionRender(text, row, index) {
        return(
            <p >
                <a href="javascript:void(0)" onClick={()=>{
                    if(row.res.startsWith("http")){
                        window.open(row.res);
                    }else {
                        message.warning("无法查看");
                    }
                }} style={{marginLeft: 10}} >查看</a>
                <a href="javascript:void(0)" onClick={()=>{
                    M.download(row.res,row.res.split("/").at(-1));
                }} style={{marginLeft: 10}} >下载</a>
            </p>
        )
    }


    viewRender(key,res_data,text, row, index){
        if(key=='name'){
            let stepName="";
            let result="";
            if(row.step==0){
                stepName="输入上传";
            }else if(row.step==1){
                stepName="输入下载";
            }else if(row.step==2){
                stepName="输入执行";
            }else if(row.step==3){
                stepName="输出上传";
            }
            if(row.errLog==null || row.errLog==""){
                result="成功";
            }else {
                result="失败";
            }
            let text=stepName+result;
            return <p style={{width: res_data[key]['width']-32,margin: 0,"overflow": "hidden","textOverflow":"ellipsis","whiteSpace": "nowrap"}}>
                <Tooltip placement="top" title={text}>
                    {text}
                </Tooltip>
            </p>


        }else{
            return <p style={{width: res_data[key]['width']-32,margin: 0,"overflow": "hidden","textOverflow":"ellipsis","whiteSpace": "nowrap"}}>
                <Tooltip placement="top" title={row[key]}>
                    {row[key]}
                </Tooltip>
            </p>
        }
    }

    inputRender(){
        const {pagination, selectedRows, selectedRowKeys } = this.state;
        return <div>
            <Form style={{"display":"flex",padding: "24px 0 0 24px"}}>
                <div style={{flex: 1,display:  'flex'}}>
                    <Popover placement={'bottomLeft'} content={this.filterContent()} trigger="hover">
                        <Button style={{"marginRight": 15,"top": 4}}>{"筛选"}</Button>
                    </Popover>
                    <Form.Item>
                        <Input key={pagination.keywords} name="keywords" style={{width: 300}}  placeholder={this.placeholder} defaultValue={pagination.keywords}/>
                    </Form.Item>
                    <Button type="primary" onClick={this.handleSearch} style={{"position":"relative","left":15,"top":3}}>搜索</Button>
                </div>
            </Form>
            <div style={{position: 'relative',top: -15,left: 25}}>
                {
                    this.tagsRender()
                }
            </div>
        </div>
    }



}











